<template>
	<view class="content">
		<view v-if="data" class="wid90 mar">
			<view style="height: 20rpx;"></view>
			<view class="foSi40 mar-bott20 fowe600 dis disAl disJuC" style="min-height: 80rpx;">{{data.title}}</view>
			<!-- <rich-text :nodes="data.content"></rich-text> -->
			<u-parse :content="data.content" />
			<view class="foSi25 mar-top40" style="color: #9a9a9a;">
				发布时间：{{data.createtime | formatDate}}
			</view>
			<view style="height: 40rpx;"></view>
		</view>
	</view>
</template>

<script>
	import uParse from '@/components/u-parse/u-parse.vue'
	import richTextUtil from '@/pages/common/richTextUtil.js';
	export default {
		components: {
		    uParse
		  },
		data() {
			return {
				data: '',
				id: ''
			}
		},
		onLoad(options) {
			this.id = options.id
			this.list()
		},
		methods: {
			preview(src, e) {
			  // do something
			},
			navigate(href, e) {
			  // do something
			},
			list: async function() {
				let that = this
				uni.request({
					url: that.global.url+'/api/news/detail',
					method: 'POST',
					data: {
						id: that.id
					},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							// 有style的写法
							var data = result.data
							data.content = richTextUtil.formatRichText(data.content);
							console.log(data);
							that.data = data
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			}
		},
		filters: {
			formatDate(value) {
				let date = new Date(value * 1000);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				return y + '-' + MM + '-' + d; //年月日
				// return y + '-' + MM + '-' + d + ' ' + h + ':' + m+ ':' + s; //年月日时分秒

			}
		}
	}
</script>

<style>
	@import url("@/components/u-parse/u-parse.css");
	.content{
		min-height: 100vh;
		background-color: #F4EDDD;
	}
	.richImg {
	    width: 100% !important;
	    height: auto !important;
	}
</style>
